using System;
using MCMLXVII.BackEnd.Services.Common.Messages;
using MCMLXVII.BackEnd.Services.SystemConfiguration.Messages;
using MCMLXVII.Core.Common.BackEnd;
using System.Collections.Specialized;
using MCMLXVII.BackEnd.Data.SystemDatabase.Parameters;
using MCMLXVII.BackEnd.Data.SystemDatabase;
using System.ServiceModel;

namespace MCMLXVII.BackEnd.Services.Core.BusinessActions
{
    public class SystemParameters
    {

        public StringNameAndValue[] GetPartitionParametersList(msgGenericItemRequest<string> PartitionName)
        {
            //NameValueCollection nv =  PartitionsManager.GetSystemParameters(PartitionName.Item);
            //StringNameAndValue[] res = new StringNameAndValue[nv.Count];
            //int i = 0;
            //foreach (string s in nv.AllKeys)
            //{
            //    res[i] = new StringNameAndValue(s, nv[s]);
            //    i++;
            //}
            //return res;
            
            throw new FaultException<BackendFault>(new BackendFault(BackendFaulType.Technical, "Not Implemented yet"));
        }


        public StringNameAndValue GetPartitionParameterInfo(msgPartitionItemRequest req)
        {
            //return new StringNameAndValue(req.ItemName, PartitionsManager.GetSystemParameter(req.PartitionName, req.ItemName));
            throw new FaultException<BackendFault>(new BackendFault(BackendFaulType.Technical, "Not Implemented yet"));
        }


        public msgSystemParameterInfo[] GetSystemParametersList(msgVoidRequest req)
        {
            SystemParameter[] par = ParametersCache.GetParameters();
            msgSystemParameterInfo[] res = new msgSystemParameterInfo[par.Length];
            int i = 0;
            foreach (SystemParameter sp in par)
            {
                switch (sp.Type)
                {
                    case SystemParameterType.ParametersVarchar:
                        res[i] = new msgSystemParameterInfo(sp.name, sp.ValueVarChar);
                        break;
                    case SystemParameterType.ParameterDatetime:
                        res[i] = new msgSystemParameterInfo(sp.name, sp.ValueDateTime);
                        break;
                    case SystemParameterType.ParameterInt:
                        res[i] = new msgSystemParameterInfo(sp.name, sp.ValueInt);
                        break;
                    case SystemParameterType.ParameterFloat:
                        res[i] = new msgSystemParameterInfo(sp.name, sp.ValueFloat);
                        break;
                    case SystemParameterType.ParameterXML:
                        res[i] = new msgSystemParameterInfo(sp.name, sp.ValueXML);
                        break;
                }
                i++;
            }
            return res;
        }

        public msgSystemParameterInfo GetSystemParameterInfo(msgGenericItemRequest<string> ParameterName)
        {
            SystemParameter sp = ParametersCache.GetParameter(ParameterName.Item) ;
            switch (sp.Type)
            {
                case SystemParameterType.ParametersVarchar:
                    return new msgSystemParameterInfo(sp.name, sp.ValueVarChar);
                case SystemParameterType.ParameterDatetime:
                    return new msgSystemParameterInfo(sp.name, sp.ValueDateTime);
                case SystemParameterType.ParameterInt:
                    return new msgSystemParameterInfo(sp.name, sp.ValueInt);
                case SystemParameterType.ParameterFloat:
                    return new msgSystemParameterInfo(sp.name, sp.ValueFloat);
                case SystemParameterType.ParameterXML:
                    return new msgSystemParameterInfo(sp.name, sp.ValueXML);
            }
            return null;
        }        
    }


}
